home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\IGNORE.C < prev    next >
C/C++ Source or Header  |  1994-12-31  |  13KB  |  570 lines

  1. /*
  2.  * ignore.c: handles the ingore command for irc 
  3.  *
  4.  * Written By Michael Sandrof
  5.  *
  6.  * Copyright(c) 1990 
  7.  *
  8.  * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 
  9.  */
  10.  
  11. #ifndef lint
  12. static    char    rcsid[] = "@(#)$Id: ignore.c,v 1.8 1994/07/02 02:32:13 mrg Stab $";
  13. #endif
  14.  
  15. #include "irc.h"
  16.  
  17. #include "ignore.h"
  18. #include "ircaux.h"
  19. #include "list.h"
  20. #include "vars.h"
  21. #include "output.h"
  22.  
  23. #define NUMBER_OF_IGNORE_LEVELS 9
  24.  
  25. #define IGNORE_REMOVE 1
  26. #define IGNORE_DONT 2
  27. #define IGNORE_HIGH -1
  28.  
  29. int    ignore_usernames = 0;
  30. char    highlight_char = '\0';
  31. static    int    ignore_usernames_sums[NUMBER_OF_IGNORE_LEVELS] =
  32.     { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  33.  
  34. static    int    remove_ignore();
  35.  
  36. /*
  37.  * Ignore: the ignore list structure,  consists of the nickname, and the type
  38.  * of ignorance which is to take place 
  39.  */
  40. typedef struct    IgnoreStru
  41. {
  42.     struct    IgnoreStru *next;
  43.     char    *nick;
  44.     int    type;
  45.     int    dont;
  46.     int    high;
  47. }    Ignore;
  48.  
  49. /* ignored_nicks: pointer to the head of the ignore list */
  50. static    Ignore *ignored_nicks = NULL;
  51.  
  52. static    int    ignore_usernames_mask(mask, thing)
  53. int    mask;
  54. int    thing;
  55. {
  56.     int    i;
  57.     int    p;
  58.  
  59.     for (i = 0, p = 1; i < NUMBER_OF_IGNORE_LEVELS; i++, p *= 2)
  60.         if (mask & p)
  61.             ignore_usernames_sums[i] += thing;
  62.  
  63.     mask = 0;
  64.     for (i = 0, p = 1; i < NUMBER_OF_IGNORE_LEVELS; i++, p *= 2)
  65.         if (ignore_usernames_sums[i])
  66.             mask += p;
  67.  
  68.     return (mask);
  69. }
  70.  
  71. /*
  72.  * ignore_nickname: adds nick to the ignore list, using type as the type of
  73.  * ignorance to take place.  
  74.  */
  75. static    void ignore_nickname(nick, type, flag)
  76. char    *nick;
  77. int    type;
  78. int    flag;
  79. {
  80.     Ignore    *new;
  81.     char    *msg,
  82.         *ptr;
  83.  
  84.     while (nick)
  85.     {
  86.         if ((ptr = index(nick, ',')) != NULL)
  87.             *ptr = '\0';
  88.         if (index(nick, '@'))
  89.             ignore_usernames = ignore_usernames_mask(type, 1);
  90.         if (*nick)
  91.         {
  92.             if (!(new = (Ignore *) list_lookup(&ignored_nicks, nick,
  93.                     !USE_WILDCARDS, !REMOVE_FROM_LIST)))
  94.             {
  95.                 if (flag == IGNORE_REMOVE)
  96.                 {
  97.                     say("%s is not on the ignorance list",
  98.                             nick);
  99.                     if (ptr)
  100.                         *(ptr++) = ',';
  101.                     nick = ptr;
  102.                     continue;
  103.                 }
  104.                 else
  105.                 {
  106.                     if ((new = (Ignore *)
  107.                         remove_from_list(&ignored_nicks,
  108.                         nick)) != NULL)
  109.                     {
  110.                         new_free(&(new->nick));
  111.                         new_free(&new);
  112.                     }
  113.                     new = (Ignore *)
  114.                         new_malloc(sizeof(Ignore));
  115.                     new->nick = (char *) 0;
  116.                     new->type = 0;
  117.                     new->dont = 0;
  118.                     new->high = 0;
  119.                     malloc_strcpy(&(new->nick), nick);
  120.                     upper(new->nick);
  121.                     add_to_list(&ignored_nicks, new);
  122.                 }
  123.             }
  124.             switch (flag)
  125.             {
  126.             case IGNORE_REMOVE:
  127.                 new->type &= (~type);
  128.                 new->high &= (~type);
  129.                 new->dont &= (~type);
  130.                 msg = "Not ignoring";
  131.                 break;
  132.             case IGNORE_DONT:
  133.                 new->dont |= type;
  134.                 new->type &= (~type);
  135.                 new->high &= (~type);
  136.                 msg = "Never ignoring";
  137.                 break;
  138.             case IGNORE_HIGH:
  139.                 new->high |= type;
  140.                 new->type &= (~type);
  141.                 new->dont &= (~type);
  142.                 msg = "Highlighting";
  143.                 break;
  144.             default:
  145.                 new->type |= type;
  146.                 new->high &= (~type);
  147.                 new->dont &= (~type);
  148.                 msg = "Ignoring";
  149.                 break;
  150.             }
  151.             if (type == IGNORE_ALL)
  152.             {
  153.                 switch (flag)
  154.                 {
  155.                 case IGNORE_REMOVE:
  156.                     say("%s removed from ignorance list",
  157.                             new->nick);
  158.                     remove_ignore(new->nick);
  159.                     break;
  160.                 case IGNORE_HIGH:
  161.                     say("Highlighting ALL messages from %s",
  162.                     new->nick);
  163.                     break;
  164.                 case IGNORE_DONT:
  165.                     say("Never ignoring messages from %s",
  166.                     new->nick);
  167.                     break;
  168.                 default:
  169.                     say("Ignoring ALL messages from %s",
  170.                     new->nick);
  171.                     break;
  172.                 }
  173.                 return;
  174.             }
  175.             else if (type)
  176.             {
  177.                 strcpy(buffer, msg);
  178.                 if (type & IGNORE_MSGS)
  179.                     strcat(buffer, " MSGS");
  180.                 if (type & IGNORE_PUBLIC)
  181.                     strcat(buffer, " PUBLIC");
  182.                 if (type & IGNORE_WALLS)
  183.                     strcat(buffer, " WALLS");
  184.                 if (type & IGNORE_WALLOPS)
  185.                     strcat(buffer, " WALLOPS");
  186.                 if (type & IGNORE_INVITES)
  187.                     strcat(buffer, " INVITES");
  188.                 if (type & IGNORE_NOTICES)
  189.                     strcat(buffer, " NOTICES");
  190.                 if (type & IGNORE_NOTES)
  191.                     strcat(buffer, " NOTES");
  192.                 if (type & IGNORE_CTCPS)
  193.                     strcat(buffer, " CTCPS");
  194.                 if (type & IGNORE_CRAP)
  195.                     strcat(buffer, " CRAP");
  196.                 say("%s from %s", buffer, new->nick);
  197.             }
  198.             if ((new->type == 0) && (new->high == 0))
  199.                 remove_ignore(new->nick);
  200.         }
  201.         if (ptr)
  202.             *(ptr++) = ',';
  203.         nick = ptr;
  204.     }
  205. }
  206.  
  207. /*
  208.  * remove_ignore: removes the given nick from the ignore list and returns 0.
  209.  * If the nick wasn't in the ignore list to begin with, 1 is returned. 
  210.  */
  211. static    int    remove_ignore(nick)
  212. char    *nick;
  213. {
  214.     Ignore    *tmp;
  215.  
  216.     if ((tmp = (Ignore *) list_lookup(&ignored_nicks, nick, !USE_WILDCARDS,
  217.             REMOVE_FROM_LIST)) != NULL)
  218.     {
  219.         if (index(nick, '@'))
  220.             ignore_usernames = ignore_usernames_mask(tmp->type, -1);
  221.         new_free(&(tmp->nick));
  222.         new_free(&tmp);
  223.         return (0);
  224.     }
  225.     return (1);
  226. }
  227.  
  228. /*
  229.  * is_ignored: checks to see if nick is being ignored (poor nick).  Checks
  230.  * against type to see if ignorance is to take place.  If nick is marked as
  231.  * IGNORE_ALL or ignorace types match, 1 is returned, otherwise 0 is
  232.  * returned.  
  233.  */
  234. int    is_ignored(nick, type)
  235. char    *nick;
  236. int    type;
  237. {
  238.     Ignore    *tmp;
  239.  
  240.     if (ignored_nicks)
  241.     {
  242.         if ((tmp = (Ignore *) list_lookup(&ignored_nicks, nick,
  243.                 USE_WILDCARDS, !REMOVE_FROM_LIST)) != NULL)
  244.         {
  245.             if (tmp->dont & type)
  246.                 return(DONT_IGNORE);
  247.             if (tmp->type & type)
  248.                 return (IGNORED);
  249.             if (tmp->high & type)
  250.                 return (HIGHLIGHTED);
  251.         }
  252.     }
  253.     return (0);
  254. }
  255.  
  256. /* ignore_list: shows the entired ignorance list */
  257. void    ignore_list(nick)
  258. char    *nick;
  259. {
  260.     Ignore    *tmp;
  261.     int    len = 0;
  262.  
  263.     if (ignored_nicks)
  264.     {
  265.         define_big_buffer(s);
  266.  
  267.         say("Ignorance List:");
  268.         if (nick)
  269.         {
  270.             len = strlen(nick);
  271.             upper(nick);
  272.         }
  273.         for (tmp = ignored_nicks; tmp; tmp = tmp->next)
  274.         {
  275.  
  276.             if (nick)
  277.             {
  278.                 if (strncmp(nick, tmp->nick, len))
  279.                     continue;
  280.             }
  281.             *buffer = (char) 0;
  282.             if (tmp->type == IGNORE_ALL)
  283.                 strmcat(buffer," ALL",BIG_BUFFER_SIZE);
  284.             else if (tmp->high == IGNORE_ALL)
  285.             {
  286.                 sprintf(s, " %cALL%c", highlight_char, 
  287.                     highlight_char);
  288.                 strmcat(buffer, s, BIG_BUFFER_SIZE);
  289.             }
  290.             else if (tmp->dont == IGNORE_ALL)
  291.                 strmcat(buffer," DONT-ALL", BIG_BUFFER_SIZE);
  292.             else
  293.             {
  294.                 if (tmp->type & IGNORE_PUBLIC)
  295.                     strmcat(buffer, " PUBLIC",
  296.                             BIG_BUFFER_SIZE);
  297.                 else if (tmp->high & IGNORE_PUBLIC)
  298.                 {
  299.                     sprintf(s, " %cPUBLIC%c",
  300.                         highlight_char, highlight_char);
  301.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  302.                 }
  303.                 else if (tmp->dont & IGNORE_PUBLIC)
  304.                     strmcat(buffer, " DONT-PUBLIC",
  305.                             BIG_BUFFER_SIZE);
  306.                 if (tmp->type & IGNORE_MSGS)
  307.                     strmcat(buffer, " MSGS",
  308.                             BIG_BUFFER_SIZE);
  309.                 else if (tmp->high & IGNORE_MSGS)
  310.                 {
  311.                     sprintf(s, " %cMSGS%c",
  312.                         highlight_char, highlight_char);
  313.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  314.                 }
  315.                 else if (tmp->dont & IGNORE_MSGS)
  316.                     strmcat(buffer, " DONT-MSGS",
  317.                             BIG_BUFFER_SIZE);
  318.                 if (tmp->type & IGNORE_WALLS)
  319.                     strmcat(buffer, " WALLS",
  320.                             BIG_BUFFER_SIZE);
  321.                 else if (tmp->high & IGNORE_WALLS)
  322.                 {
  323.                     sprintf(s, " %cWALLS%c",
  324.                         highlight_char, highlight_char);
  325.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  326.                 }
  327.                 else if (tmp->dont & IGNORE_WALLS)
  328.                     strmcat(buffer, " DONT-WALLS",
  329.                             BIG_BUFFER_SIZE);
  330.                 if (tmp->type & IGNORE_WALLOPS)
  331.                     strmcat(buffer, " WALLOPS",
  332.                             BIG_BUFFER_SIZE);
  333.                 else if (tmp->high & IGNORE_WALLOPS)
  334.                 {
  335.                     sprintf(s, " %cWALLOPS%c",
  336.                         highlight_char, highlight_char);
  337.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  338.                 }
  339.                 else if (tmp->dont & IGNORE_WALLOPS)
  340.                     strmcat(buffer, " DONT-WALLOPS",
  341.                             BIG_BUFFER_SIZE);
  342.                 if (tmp->type & IGNORE_INVITES)
  343.                     strmcat(buffer, " INVITES",
  344.                             BIG_BUFFER_SIZE);
  345.                 else if (tmp->high & IGNORE_INVITES)
  346.                 {
  347.                     sprintf(s, " %cINVITES%c",
  348.                         highlight_char, highlight_char);
  349.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  350.                 }
  351.                 else if (tmp->dont & IGNORE_INVITES)
  352.                     strmcat(buffer, " DONT-INVITES",
  353.                             BIG_BUFFER_SIZE);
  354.                 if (tmp->type & IGNORE_NOTICES)
  355.                     strmcat(buffer, " NOTICES",
  356.                             BIG_BUFFER_SIZE);
  357.                 else if (tmp->high & IGNORE_NOTICES)
  358.                 {
  359.                     sprintf(s, " %cNOTICES%c",
  360.                         highlight_char, highlight_char);
  361.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  362.                 }
  363.                 else if (tmp->dont & IGNORE_NOTICES)
  364.                     strmcat(buffer, " DONT-NOTICES",
  365.                             BIG_BUFFER_SIZE);
  366.                 if (tmp->type & IGNORE_NOTES)
  367.                     strmcat(buffer, " NOTES",
  368.                             BIG_BUFFER_SIZE);
  369.                 else if (tmp->high & IGNORE_NOTES)
  370.                 {
  371.                     sprintf(s, " %cNOTES%c",
  372.                         highlight_char, highlight_char);
  373.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  374.                 }
  375.                 else if (tmp->dont & IGNORE_NOTES)
  376.                     strmcat(buffer, " DONT-NOTES",
  377.                             BIG_BUFFER_SIZE);
  378.                 if (tmp->type & IGNORE_CTCPS)
  379.                     strmcat(buffer, " CTCPS",
  380.                             BIG_BUFFER_SIZE);
  381.                 else if (tmp->high & IGNORE_CTCPS)
  382.                 {
  383.                     sprintf(s, " %cCTCPS%c",
  384.                         highlight_char, highlight_char);
  385.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  386.                 }
  387.                 else if (tmp->dont & IGNORE_CTCPS)
  388.                     strmcat(buffer, " DONT-CTCPS",
  389.                             BIG_BUFFER_SIZE);
  390.                 if (tmp->type & IGNORE_CRAP)
  391.                     strmcat(buffer, " CRAP",
  392.                             BIG_BUFFER_SIZE);
  393.                 else if (tmp->high & IGNORE_CRAP)
  394.                 {
  395.                     sprintf(s, " %cCRAP%c",
  396.                         highlight_char, highlight_char);
  397.                     strmcat(buffer, s, BIG_BUFFER_SIZE);
  398.                 }
  399.                 else if (tmp->dont & IGNORE_CRAP)
  400.                     strmcat(buffer, " DONT-CRAP",
  401.                             BIG_BUFFER_SIZE);
  402.             }
  403.             say("\t%s:\t%s", tmp->nick, buffer);
  404.         }
  405.         free_big_buffer(s);
  406.     }
  407.     else
  408.         say("There are no nicknames being ignored");
  409. }
  410.  
  411. /*
  412.  * ignore: does the /IGNORE command.  Figures out what type of ignoring the
  413.  * user wants to do and calls the proper ignorance command to do it. 
  414.  */
  415. /*ARGSUSED*/
  416. void    ignore(command, args)
  417. char    *command,
  418.     *args;
  419. {
  420.     char    *nick,
  421.         *type;
  422.     int    len;
  423.     int    flag,
  424.         no_flags;
  425.  
  426.     if ((nick = next_arg(args, &args)) != NULL)
  427.     {
  428.         no_flags = 1;
  429.         while ((type = next_arg(args, &args)) != NULL)
  430.         {
  431.             no_flags = 0;
  432.             upper(type);
  433.             switch (*type)
  434.             {
  435.             case '^':
  436.                 flag = IGNORE_DONT;
  437.                 type++;
  438.                 break;
  439.             case '-':
  440.                 flag = IGNORE_REMOVE;
  441.                 type++;
  442.                 break;
  443.             case '+':
  444.                 flag = IGNORE_HIGH;
  445.                 type++;
  446.                 break;
  447.             default:
  448.                 flag = 0;
  449.                 break;
  450.             }
  451.             if ((len = strlen(type)) == 0)
  452.             {
  453.                 say("You must specify one of the following:");
  454.                 say("\tALL MSGS PUBLIC WALLS WALLOPS INVITES \
  455. NOTICES NOTES NONE");
  456.                 return;
  457.             }
  458.             if (strncmp(type, "ALL", len) == 0)
  459.                 ignore_nickname(nick, IGNORE_ALL, flag);
  460.             else if (strncmp(type, "MSGS", len) == 0)
  461.                 ignore_nickname(nick, IGNORE_MSGS, flag);
  462.             else if (strncmp(type, "PUBLIC", len) == 0)
  463.                 ignore_nickname(nick, IGNORE_PUBLIC, flag);
  464.             else if (strncmp(type, "WALLS", len) == 0)
  465.                 ignore_nickname(nick, IGNORE_WALLS, flag);
  466.             else if (strncmp(type, "WALLOPS", len) == 0)
  467.                 ignore_nickname(nick, IGNORE_WALLOPS, flag);
  468.             else if (strncmp(type, "INVITES", len) == 0)
  469.                 ignore_nickname(nick, IGNORE_INVITES, flag);
  470.             else if (strncmp(type, "NOTICES", len) == 0)
  471.                 ignore_nickname(nick, IGNORE_NOTICES, flag);
  472.             else if (strncmp(type, "NOTES", len) == 0)
  473.                 ignore_nickname(nick, IGNORE_NOTES, flag);
  474.             else if (strncmp(type, "CTCPS", len) == 0)
  475.                 ignore_nickname(nick, IGNORE_CTCPS, flag);
  476.             else if (strncmp(type, "CRAP", len) == 0)
  477.                 ignore_nickname(nick, IGNORE_CRAP, flag);
  478.             else if (strncmp(type, "NONE", len) == 0)
  479.             {
  480.                 char    *ptr;
  481.  
  482.                 while (nick)
  483.                 {
  484.                     if ((ptr = index(nick, ',')) != NULL)
  485.                         *ptr = (char) 0;
  486.                     if (*nick)
  487.                     {
  488.                         if (remove_ignore(nick))
  489.                 say("%s is not in the ignorance list!", nick);
  490.                         else
  491.                 say("%s removed from ignorance list", nick);
  492.                     }
  493.                     if (ptr)
  494.                         *(ptr++) = ',';
  495.                     nick = ptr;
  496.                 }
  497.             }
  498.             else
  499.             {
  500.                 say("You must specify one of the following:");
  501.                 say("\tALL MSGS PUBLIC WALLS WALLOPS INVITES \
  502. NOTICES NOTES CTCPS CRAP NONE");
  503.             }
  504.         }
  505.         if (no_flags)
  506.             ignore_list(nick);
  507.     } else
  508.         ignore_list((char *) 0);
  509. }
  510.  
  511. /*
  512.  * set_highlight_char: what the name says..  the character to use
  513.  * for highlighting..  either BOLD, INVERSE, or UNDERLINE..
  514.  */
  515. void    set_highlight_char(s)
  516. char    *s;
  517. {
  518.     int    len;
  519.  
  520.     len = strlen(s);
  521.  
  522.     if (!my_strnicmp(s, "BOLD", len))
  523.     {
  524.         set_string_var(HIGHLIGHT_CHAR_VAR, "BOLD");
  525.         highlight_char = BOLD_TOG;
  526.     }
  527.     else if (!my_strnicmp(s, "INVERSE", len))
  528.     {
  529.         set_string_var(HIGHLIGHT_CHAR_VAR, "INVERSE");
  530.         highlight_char = REV_TOG;
  531.     }
  532.     else if (!my_strnicmp(s, "UNDERLINE", len))
  533.     {
  534.         set_string_var(HIGHLIGHT_CHAR_VAR, "UNDERLINE");
  535.         highlight_char = UND_TOG;
  536.     }
  537.     else
  538.         say("HIGHLIGHT_CHAR must be one of BOLD, INVERSE, or \
  539.             UNDERLINE");
  540. }
  541.  
  542. int     ignore_combo(flag1, flag2)
  543. int     flag1;
  544. int     flag2;
  545. {
  546.         if (flag1 == DONT_IGNORE || flag2 == DONT_IGNORE)
  547.                 return DONT_IGNORE;
  548.         if (flag1 == IGNORED || flag2 == IGNORED)
  549.                 return IGNORED;
  550.         if (flag1 == HIGHLIGHTED || flag2 == HIGHLIGHTED)
  551.                 return HIGHLIGHTED;
  552.         return 0;
  553. }
  554.  
  555. /*
  556.  * double_ignore - makes live simpiler when using doing ignore code
  557.  * added, april 1993, phone.
  558.  */
  559. int    double_ignore(nick, userhost, type)
  560. char    *nick,
  561.     *userhost;
  562. int    type;
  563. {
  564.     if (userhost)
  565.         return (ignore_combo(is_ignored(nick, type),
  566.             is_ignored(userhost, type)));
  567.     else
  568.         return (is_ignored(nick, type));
  569. }
  570.